package cn.xz.xy.dialog

import android.view.Gravity
import android.widget.TextView
import cn.xz.xy.R
import cn.xz.xy.base.BaseDialogRxFragment

/**
 * 全部操作提示弹窗
 * */
class AllClickDialog: BaseDialogRxFragment() {

    private var mClickListener: OnClickListener? = null

    private var tvTxt: TextView? = null
    private var tvYes: TextView? = null
    private var tvNo: TextView? = null

    private var isOpen: Boolean = true

    companion object {
        fun newInstance(
            isOpen: Boolean,
            clickListener: OnClickListener
        ): AllClickDialog {
            val dialog = AllClickDialog()
            dialog.isOpen = isOpen
            dialog.mClickListener = clickListener
            return dialog
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_click_all
    }

    override fun configDialog() {
        this.setDialogSize(gravity = Gravity.CENTER,width = 300)
    }

    override fun initViews() {

        dialog?.let {
            tvTxt = it.findViewById(R.id.tv_txt)
            tvYes = it.findViewById(R.id.tv_yes)
            tvNo = it.findViewById(R.id.tv_no)
        }

        //点击外部不隐藏
        /*dialog?.setCancelable(false)
        dialog?.setCanceledOnTouchOutside(false)*/
        //视图相关
        initUI()
        //点击事件
        initEvent()
    }

    private fun initUI(){
        if (isOpen){
            tvTxt?.text = "是否全部开启?"
        }else{
            tvTxt?.text = "是否全部关闭?"
        }
    }

    private fun initEvent(){
        tvYes?.setOnClickListener {
            mClickListener?.onYes()
            dismiss()
        }
        tvNo?.setOnClickListener {
            mClickListener?.onNo()
            dismiss()
        }
    }


    interface OnClickListener {
        fun onYes()
        fun onNo()
    }

}